package com.shujia.flink.tf

import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala._

object Demo1Map {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    //读取数据
    val studentDS: DataStream[String] = env.readTextFile("data/students.txt")

    //scala api写法
    val scalaDS: DataStream[String] = studentDS.map(stu => {
      val split: Array[String] = stu.split(",")
      split(4)
    })
    //scalaDS.print()

    val javaDS: DataStream[String] = studentDS.map(new MapFunction[String, String] {
      /**
       * map: 每一条数据执行一次
       *
       * @param stu : 一行数据
       * @return
       */
      override def map(stu: String): String = {
        val split: Array[String] = stu.split(",")
        split(4)
      }
    })

    javaDS.print()


    env.execute()

  }
}
